--Bai tap 5: nhap vao 2 so, tinh tong 2 so
create proc usp_TinhTong
    @s1 int,
    @s2 int
as
    begin
        declare @tg int
        Set @tg = @s1 + @s2
        print @tg
    end    
Go

exec usp_TinhTong 7, 8

alter proc usp_TinhTong
    @s1 int,
    @s2 int,
    @tg int output
as
    begin
        Set @tg = @s1 + @s2
    end    
Go

declare @tong_output int
exec usp_TinhTong 7, 9, @tong_output output
print @tong_output

alter proc usp_TinhTong
    @s1 int,
    @s2 int
as
    begin
        declare @tg int
        set @tg = @s1 + @s2
        return @tg
    end    
go

declare @tong_return int
exec @tong_return = usp_TinhTong 7, 10
print @tong_return

--Bai tap 6: Nhap vao 2 so @s1 va @s2, in ra cau: Tong la: @tg
alter proc usp_TinhTong
    @s1 int,
    @s2 int
as
    begin
        declare @tg int
        set @tg = @s1 + @s2
        print ' Tong cua 2 so da cho la: ' + cast(@tg as char)
    end    
go

exec usp_TinhTong 2000000, 4442
go

--Bai tap 9: nhap vao 2 so, in ra so lon nhat
alter proc usp_InMax
    @s1 int,
    @s2 int
as
    begin
        if @s1 > @s2
            print @s1
        else if @s1 < @s2
            print @s2
        else
            print N'Hai s? b?ng nhau'
    end
go

exec usp_InMax 67, 9
go

--Bai tap 10: nhap vao 2 so, in ra dong...
alter proc usp_InMax
    @s1 int,
    @s2 int
as
    begin
        declare @max int
        if @s1 > @s2
            set @max = @s1
        else if @s1 < @s2
            set @max = @s2
        else
            begin
                print N'Hai s? b?ng nhau'
                return
            end
        print 'So lon nhat cua ' + cast(@s1 as varchar) + ' va ' + cast(@s2 as varchar) + ' la ' + cast(@max as char)
    end
go

exec usp_InMax 4, 4
go

--Bai tap 11: 
create proc usp_InMaxMin
    @s1 int,
    @s2 int,
    @max int out,
    @min int out
as
    begin
        if @s1 > @s2
            begin
                set @max = @s1
                set @min = @s2
            end
        else if @s1 < @s2
            begin
                set @max = @s2
                set @min = @s1
            end
        else
            begin
                print N'Hai s? b?ng nhau'
                return
            end
    end
go

declare @min int
declare @max int
exec usp_InMaxMin 4, 6, @max out, @min out
print @min
print @max
go

--Bai tap 12: 
alter proc usp_InSoNguyen
    @n int
as
    begin
        declare @i int
        set @i = 1
        while @i <= @n
            begin 
                print @i
                set @i = @i + 1
            end
    end
go

exec usp_InSoNguyen 9

--Bai tap 13: 
create proc usp_InSoNguyenChan
    @n int
as 
    begin
        declare @i int
        set @i = 1
        while @i <= @n
            begin
                if @i % 2 = 0
                    print @i
                set @i = @i + 1
            end
    end
go

exec usp_InSoNguyenChan 9
go